package com.aca.market.util;

import com.aca.market.entity.Indent;
import com.aca.market.service.IIndentService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.concurrent.CountDownLatch;

public class TestThread extends Thread{

    IIndentService indentService;

    private CountDownLatch latch;

    public TestThread(CountDownLatch latch,IIndentService indentService){
        this.indentService = indentService;
        this.latch = latch;
    }

    @Override
    public void run() {

//        try {
        System.out.println("===============1" + getName() + ":" + LocalDateTime.now());
        BigDecimal payment = indentService.getById(15L).getPayment();
        indentService.update(new UpdateWrapper<Indent>().eq("indent_id", 15L).set("payment", payment.add(BigDecimal.TEN)));
//            Thread.sleep(5000);
        System.out.println("===============2" + getName() + ":" + LocalDateTime.now());
        indentService.update(new UpdateWrapper<Indent>().eq("indent_id", 15L).set("payment", payment.subtract(BigDecimal.ONE)));
        System.out.println(LocalDateTime.now()+" : "+indentService.getById(15L));
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("===============3"+getName()+":"+LocalDateTime.now());
        latch.countDown();
    }
}
